<script language="javascript" type="text/javascript">

$().ready(function() {
	$('textarea').tinymce({
		// Location of TinyMCE script
		script_url : 'admin/j/3/tiny_mce/tiny_mce.js',

		// General options
		theme : "advanced",
			plugins : "save,safari,layer,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,pagebreak",
		theme_advanced_buttons1 : "save,fullscreen,code,formatselect,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,link,unlink,image,cleanup,hr,visualaid,charmap,media,attribs,table,removeformat,preview,blockquote",

		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",

		theme_advanced_resize_horizontal : false,
		theme_advanced_resizing : true,
		apply_source_formatting : true,
		height:"350px",


		content_css : "admin/c/tinymce-modified.css",
		document_base_url : "<?PHP echo 'http://'.$_SERVER['HTTP_HOST'].$conf->path;?>"
	});
	
	$("#editor-edit").hide();
	
	$(".add-h1").click(
		function(){
			var  str = $(this).attr('id');
			var info = str.split('-');
			
			 $.ajax({
								type: "POST",
								url: "a/process-editor.php",
								async:false,
								data: {'function':'add-count','page':info[0],'type':info[1],'count':info[2]},
								dataType: "json",
							   success:
							   function(){
							   	
							   }
		 });
		 
 		 setTimeout("location.reload(true);",1000);
		}
	
	);
	$(".remove-h1").click(
		function(){
			var  str = $(this).attr('id');
			var info = str.split('-');
			
			 $.ajax({
								type: "POST",
								url: "a/process-editor.php",
								async:false,
								data: {'function':'remove-count','page':info[0],'type':info[1],'count':info[2]},
								dataType: "json",
							   success:
							   function(){
							   	
							   }
		 });
		 
 		 setTimeout("location.reload(true);",1000);
		}
	
	);
	$(".rmv-post-count").click(
		function(){
			var  str = $(this).attr('id');
			var info = str.split('-');
			
			 $.ajax({
								type: "POST",
								url: "a/process-editor.php",
								async:false,
								data: {'function':'remove-artc','page':info[0],'type':info[1],'count':info[2]},
								dataType: "json",
							   success:
							   function(){
							   	
							   }
		 });
		 
 		 setTimeout("location.reload(true);",1000);
		}
	
	);
	$("#control-e").click(
		function(){
			$("#editor-edit").hide();
			$("#editor-controls").show();
		}
	
	);
	$("#edit-e").click(
		function(){
			$("#editor-controls").hide();
			$("#editor-edit").show();
		}
	
	);
	$("#post-type").val('<?PHP echo $ptype ?>').attr('selected',true); 		
		<?PHP
			if(!$edit):
		?>
				$("#editor-title").html("Add new "+$("#post-type option:selected").text());
		<?PHP
		   else:
	   ?>
				$("#editor-title").html("Edit");
	   <?PHP
		   endif;		
		?>
 		$("#post-type").change(function(){
 			document.location.href='editor'+'?ptype='+$("#post-type option:selected").text()+'&cmd=add';
 		});
		$("#add_new").click(function(){
 			document.location.href='editor'+'?ptype='+$("#post-type option:selected").text()+'&cmd=add';
 		});
 		
 		
 		$(".h1-edit-select").click(function(){
 		 var replacement_id = $(this).parent().children('select').children('option:selected').attr('value');
 		 var current_id = $(this).parent().prev().attr('id');
 		 $.ajax({
								type: "POST",
								url: "a/process-editor.php",
								async:false,
								data: {'function':'replaceh1','current':current_id,'replacement':replacement_id},
								dataType: "json",
							   success:
							   function(){
							   	alert('headline-replaced');
							   }
		 });
		 
 		 setTimeout("location.reload(true);",1000);
 		});
 		$(".d1-edit-select").click(function(){
 		 var replacement_id = $(this).parent().children('select').children('option:selected').attr('value');
 		 var current_id = $(this).parent().prev().attr('id');
 		 $.ajax({
								type: "POST",
								url: "a/process-editor.php",
								async:false,
								data: {'function':'replaced1','current':current_id,'replacement':replacement_id},
								dataType: "json",
							   success:
							   function(){
							   	alert('headline-replaced');
							   }
		 });
		 
 		 setTimeout("location.reload(true);",1000);
 		});
 		$(".a-edit-select").click(function(){
 		 var replacement_id = $(this).parent().children('select').children('option:selected').attr('value');
 		 var current_id = $(this).parent().prev().attr('id');
 		 $.ajax({
								type: "POST",
								url: "a/process-editor.php",
								async:false,
								data: {'function':'replace-wa','current':current_id,'replacement':replacement_id},
								dataType: "json",
							   success:
							   function(){
							   	alert('article-replaced');
							   }
		 });
		 
 		 setTimeout("location.reload(true);",1000);
 		});
 		$(".r-edit-select").click(function(){
 		 var replacement_id = $(this).parent().children('select').children('option:selected').attr('value');
 		 var current_id = $(this).parent().prev().attr('id');
 		 $.ajax({
								type: "POST",
								url: "a/process-editor.php",
								async:false,
								data: {'function':'replace-wa','current':current_id,'replacement':replacement_id},
								dataType: "json",
							   success:
							   function(){
							   	alert('article-replaced');
							   }
		 });
		 
 		 setTimeout("location.reload(true);",1000);
 		});
 		$(".b-edit-select").click(function(){
 		 var replacement_id = $(this).parent().children('select').children('option:selected').attr('value');
 		 var current_id = $(this).parent().prev().attr('id');
 		 $.ajax({
								type: "POST",
								url: "a/process-editor.php",
								async:false,
								data: {'function':'replace-wa','current':current_id,'replacement':replacement_id},
								dataType: "json",
							   success:
							   function(){
							   	alert('article-replaced');
							   }
		 });
		 
 		 setTimeout("location.reload(true);",1000);
 		});
		$(".n-edit-select").click(function(){
 		 var replacement_id = $(this).parent().children('select').children('option:selected').attr('value');
 		 var current_id = $(this).parent().prev().attr('id');
 		 $.ajax({
								type: "POST",
								url: "a/process-editor.php",
								async:false,
								data: {'function':'replace-wa','current':current_id,'replacement':replacement_id},
								dataType: "json",
							   success:
							   function(){
							   	alert('article-replaced');
							   }
		 });
		 
 		 setTimeout("location.reload(true);",1000);
 		});
});


</script>
